package me.kagami.exex;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import me.kagami.exex.intercepter.InsertDataIntercepter;
import me.kagami.exex.registry.CellStyleService;
import me.kagami.exex.util.ClassUtil;

public class Context {
	private Workbook workbook = null;
	private List<?> dataList = null;
	private List<CellStyle> cellStyleList = new ArrayList<>();
	private CellStyleService cellStyleService = new CellStyleService();
	private List<InsertDataIntercepter> intercepters = new ArrayList<>();

	public Context(Workbook workbook, List<?> dataList) {
		this.workbook = workbook;
		this.dataList = dataList;
	}

	public Workbook getWorkbook() {
		return workbook;
	}

	public List<?> getDataList() {
		return dataList;
	}

	public List<Field> getDataFields(int i) {
		return ClassUtil.getFieldsList(dataList.get(i));
	}

	public List<CellStyle> getCellStyleList() {
		return cellStyleList;
	}

	public void initCellStyleList(Sheet sheet) {
		cellStyleList = cellStyleService.initCellStyleList(sheet);
	}

	public void addIntercepter(InsertDataIntercepter intercepter) {
		intercepter.setContext(this);
		this.intercepters.add(intercepter);
	}

	public List<InsertDataIntercepter> getIntercepters() {
		return intercepters;
	}

}
